import { stringify } from 'qs';
import _ from 'lodash';
import request from '../utils/request';
import { Constants } from '../utils';
import { ipConfig } from './config';

const serverName = ipConfig.baseServerName();

/**
 * 设备接口配置
 *
 */
const configPath = {
  queryEquipmentByparams: `${serverName}/device/equipment/queryEquipmentByparams`,
  historyByEqpId: `${serverName}/device/fualt/historyByEqpCode`,
  queryEquipmentByEquipmentId: `${serverName}/device/equipment/queryEquipmentByEquipmentCode`,
  downloadImg: `${ipConfig.url(`${serverName}/logistics/fileController/download`)}`,
  queryEquipmentByEquipmentCode: `${serverName}/device/equipment/queryEquipmentByEquipmentCode`,
  findEquipmentAssetByCode: `${serverName}/device/assets/findEquipmentAssetByCode`,
  updateEquipmentImage: `${serverName}/device/equipment/updateEquipmentImage`,
  querySysParams: '/api-ms/system/parameters/searchWithFilters',
};

export const getDownloadImg = configPath.downloadImg;
/**
 * 设备搜索列表查询接口
 * @param {*} params 查询配置参数
 */
export const getQueryEquipmentByparams = async params => {
  const url = `${ipConfig.url(configPath.queryEquipmentByparams)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};

/**
 * 设备检维修历史查询接口
 * @param {*} params 查询参数配置
 */
export const getHistoryByEqpId = async params => {
  const url = `${ipConfig.url(configPath.historyByEqpId)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};

/**
 * 设备信息查询接口
 * @param {*} params
 */
export const getQueryEquipmentByEquipmentId = async params => {
  // const url = `${ipConfig.url(configPath.queryEquipmentByEquipmentId)}?${stringify(params)}`;
  const url = `${ipConfig.url(configPath.queryEquipmentByEquipmentId)}`;
  return request(url, {
    method: 'POST',
    body: {
      equipmentCode: params,
    },
  }).then();
};

/**
 * 通过扫描二维码code 查询设备信息接口
 * @param {*} params
 */
export const getqueryEquipmentByEquipmentCode = async params => {
  const url = `${ipConfig.url(configPath.queryEquipmentByEquipmentCode)}`;
  return request(url, {
    method: 'POST',
    body: {
      equipmentCode: params,
    },
  }).then();
};

/**
 *  查询设备资产信息接口
 * @param {*} params
 */
export const getFindEquipmentAssetByCode = async params => {
  const url = `${ipConfig.url(configPath.findEquipmentAssetByCode)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
/**
 *  修改设备图片
 * @param {*} params
 */
export const getUpdateEquipmentImage = async params => {
  const url = `${ipConfig.url(configPath.updateEquipmentImage)}?${stringify(params)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
/**
 *  查询角色信息
 * @param {*} params
 */
export const getQueryRoles = async params => {
  const url = `${ipConfig.url('/api-ms/system/users/')}${params}/roles`;
  return request(url, {
    method: 'GET',
  }).then();
};
/**
 *  查询安全部门信息
 * @param {*} params
 */
export const getQuerySageDepInfo = async () => {
  const url = `${ipConfig.url(`${serverName}/device/equipment/findSafeOrgByUserFact`)}`;
  return request(url, {
    method: 'GET',
  }).then();
};
/**
 *  查询系统参数
 * @param {*} params
 */
export const getQuerySysParams = async params => {
  const url = `${ipConfig.url(configPath.querySysParams)}?rows=9999&page=1&data={"sord":"desc","sidx":"createTime","filters":{"groupOp":"and","rules":[{"field":"paraName","op":"cn","data":"sysMenuPower"}]}}`;
  return request(url, {
    method: 'GET',
  }).then();
};
